<?php
require "constants.php";

$get = array_merge($_GET,$_POST);
$kword = strtolower($get["keyword"]);
$result = array();

$articles = array(
	array(
	"score" => 3,
	"id" => 1,
	"author" => "Matt Sullivan",
	"title" => "Steve Jobs",
	"parent" => ""),

	array(
	"score" => 2,
	"id" => 2,
	"author" => "Carlos Tévez",
	"title" => "I want to leave Manchester City because I want to live closer to my family",
	"parent" => "Carlos Tevez to leave Manchester City"),

	array(
	"score" => 0,
	"id" => 3,
	"author" => "Manchester City",
	"title" => "Manchester City agree Carlos Tevez sale to Corinthians",
	"parent" => "Carlos Tevez to leave Manchester City"),

	array(
	"score" => 0,
	"id" => 4,
	"author" => "Matt Sullivan, reporting from the stands of Frankfurt Arena",
	"title" => "Women's World Cup final: Japan beat USA on penalties",
	"parent" => ""),

	array(
	"score" => 45,
	"id" => 5,
	"author" => "Daniel Maurer",
	"title" => "Park Slope's Nameless Café Opens on Lower East Side and Finally Gets a Name Park Slope's Nameless C",
	"parent" => ""),

	array(
	"score" => 0,
	"id" => 6,
	"author" => "Senior design engineer at Kusch Yachts, Germany",
	"title" => "Equatorial Guinea's dictator's son has ordered a $380mln mega-yacht from my company",
	"parent" => ""),

	array(
	"score" => 1234,
	"id" => 7,
	"author" => "John Williams",
	"title" => "Gamal Mubarak spotted in London",
	"parent" => ""),

	array(
	"score" => 1677,
	"id" => 8,
	"author" => "Mamdouh Habib",
	"title" => "My capture and move to Guantano Bay, and later release",
	"parent" => ""),

	array(
	"score" => 1,
	"id" => 9,
	"author" => "Tadrian Ainsley",
	"title" => "I've resigned from EDF Trading",
	"parent" => ""),

	array(
	"score" => 0,
	"id" => 10,
	"author" => "Herman Ludrer, CEO, Bubbles and Beyond",
	"title" => "We have closed a new financing round, and will expand our international market position",
	"parent" => ""),

	array(
	"score" => 0,
	"id" => 11,
	"author" => "US Federal Reserve Board",
	"title" => "We are extending existing temporary U.S. dollar liquidity swap arrangements through August 1, 2012.",
	"parent" => ""),

	array(
	"score" => 0,
	"id" => 12,
	"author" => "Rowan Moore, Art Critic.",
	"title" => "Assemble's ingenious Folly for a Flyover is one of three new works currently enhancing London's publ",
	"parent" => ""),

	array(
	"score" => 1677,
	"id" => 13,
	"author" => "Mamdouh Habib",
	"title" => "My capture and move to Guantano Bay, and later release",
	"parent" => ""),

	array(
	"score" => 1234,
	"id" => 14,
	"author" => "John Williams",
	"title" => "Gamal Mubarak spotted in London",
	"parent" => ""),

	array(
	"score" => 445,
	"id" => 15,
	"author" => "Jean-Fabrice Mathieu",
	"title" => "Cuba prevents tourists from bringing DVD players into the country for fear of Western propaganda",
	"parent" => ""),

	array(
	"score" => 0,
	"id" => 16,
	"author" => "Manchester City",
	"title" => "Manchester City agree Carlos Tevez sale to Corinthians",
	"parent" => "Carlos Tevez to leave Manchester City"),

	array(
	"score" => 1,
	"id" => 17,
	"author" => "Tadrian Ainsley",
	"title" => "I've resigned from EDF Trading",
	"parent" => ""),

	array(
	"score" => 0,
	"id" => 18,
	"author" => "Gyanesh Pandey",
	"title" => "We are helping electrify India with rice husk",
	"parent" => ""),

	array(
	"score" => 0,
	"id" => 19,
	"author" => "Herman Ludrer, CEO, Bubbles and Beyond",
	"title" => "We have closed a new financing round, and will expand our international market position",
	"parent" => ""),

	array(
	"score" => 0,
	"id" => 20,
	"author" => "Matt Sullivan",
	"title" => "committee to protect journalists",
	"parent" => "")
);

if($kword){
	foreach($articles as $article){
		if(strstr(strtolower($article["author"]),$kword) || strstr(strtolower($article["title"]),$kword) || strstr(strtolower($article["parent"]),$kword)){
			$article["link"] = BASE."/article/".$article["id"];
			$result[] = $article;
		}
	}
}

echo json_encode($result);

?>